package com.cskaoyan.Day23;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.UnknownHostException;

class ReceiveTask implements  Runnable{

    DatagramSocket datagramSocket;

    public ReceiveTask(DatagramSocket datagramSocket) {
        this.datagramSocket = datagramSocket;
    }
    @Override
    public void run() {

        while (true){
            try {
                DatagramPacket receiveDataPacket = UDPUtils.getReceivePacket();
                datagramSocket.receive(receiveDataPacket);
                UDPUtils.parseSendData(receiveDataPacket);
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}